package com.eyas.business.controllor.rechargeinfo;

import com.eyas.business.model.jdbcEntity.table.RechargeInfo;
import com.eyas.business.model.pojo.rechargeinfo.QueryParamDTO;
import com.eyas.business.model.pojo.rechargeinfo.QueryResultDTO;
import com.eyas.business.service.rechargeinfo.RechargeInfoService;
import com.eyas.business.service.userinfo.UserInfoService;
import com.eyas.core.model.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Auther: 王龙龙
 * @Date: 2019/3/16 11:14
 * @Description:
 */
@Controller
@RequestMapping("/eyas/rechargeinfo/")
public class RechargeInfoAction {
    @Autowired
    private RechargeInfoService rechargeInfoService;

    @Autowired
    private UserInfoService userInfoService;


    @RequestMapping("/edit")
    public String edit(int userid, Model model) {
        model.addAttribute("userid",userid);
        return "/rechargeinfo/edit";
    }

    @PostMapping("/saveRechageInfo")
    @ResponseBody
    public String saveRechageInfo(RechargeInfo rechargeInfo, HttpSession session) {
        this.rechargeInfoService.saveRechageInfo(rechargeInfo,session);
        return "{\"success\":true}";
    }

    @GetMapping("/queryRechargeInfo")
    @ResponseBody
    public PageResult<QueryResultDTO> queryRechargeInfo(QueryParamDTO paramDTO,
                                                        @RequestParam(defaultValue = "1") int page,
                                                        @RequestParam(defaultValue = "10") int limit) {
        PageResult<QueryResultDTO> result = this.rechargeInfoService.queryRechargeInfo(paramDTO,page-1,limit);
        return result;
    }
}
